<?php

namespace app\api\controller;

use app\api\model\Book as BookModel;
use app\BaseController;

class Book extends BaseController
{
    /* 自动加载 */
    public function initialize()
    {
        $this->uid = $this->request->uid;
    }

    /* 添加 */
    public function add()
    {
        if (!$this->request->auth) return show(config('status.auth'), 'Authorization Failed');
        $cid = input('cid', '');
        $gid = input('gid', '');
        $date = input('date', 0, 'intval');
        $content = input('content', '');
        $tel = input('tel', '');
        $time = time();
        BookModel::create([
            'cid' => $cid,
            'uid' => $this->uid,
            'gid' => $gid,
            'date' => $date,
            'content' => $content,
            'tel' => $tel,
            'time' => $time
        ]);
        return show(config('status.success'), '预约信息已提交');
    }
}
